<template>
	<view class="content">
		<view class="top_div">
			<view class="top_left_div">当前科目:
			<text style="color: #333333; margin-left: 20rpx;">
			{{currCourse}}
			</text></view>
			  <view class="top_right_div" @click="selCourse">
				<image src="../../static/tk_icon_switch_lj.png"></image>
				<text>切换科目</text>
			</view>  
		</view>
		<list class="paper_list">
			<cell class="paper_item" v-for="(item,index) in dataList"
			                          @tap="examDetail(index)">
				<view class="item_left">
					<view class="paper_title">{{item.title}}</view>
					<view class="paper_time">
						<text>考试时长:<text style="color: #333333;">{{item.duration}}分钟</text> </text> 
						<text>开始时间:<text style="color: #333333;">{{item.createTime}}</text> </text> 
					</view>
				</view>
				<view class="item_right">
					
					<text v-if="item.state=='已过期'" class="gray_bg">{{item.state}}</text> 
					<text v-if="item.state=='未开始'" class="green_bg">{{item.state}}</text> 
					<text v-if="item.state=='考试中'" class="red_bg">{{item.state}}</text>
				</view>
			</cell>
		</list>
		
		
		
		<popCourse v-show="bottomSHow" :courseList="courseList" @courseItemClicks="courseItem"></popCourse>
	</view>
</template>

<script>
	import popCourse from '../../components/course/course.vue';
	export default{
		components: {
			popCourse
		},
		data(){
			return{ 
				cid:uni.getStorageSync('cid'),
				bottomSHow: false,//是否显示选择课程
				currCourse:uni.getStorageSync('cname'),//当前课程
				courseList:[],
				dataList:[
					
					/* {"id":1,"title":"阿里云期中模拟测试","dur":20,"startTime":"2021-10-02 20:10:10",statu:"已结束"},
					{"id":2,"title":"阿里云期中模拟测试2","dur":15,"startTime":"2021-10-05 20:10:10",statu:"未开始"},
					{"id":2,"title":"阿里云期中模拟测试3","dur":15,"startTime":"2021-10-05 20:10:10",statu:"进行中"}
				 */
				]
				
			}
		},onReady: function() {
			this.initExamList();
			//初始化所有的的课程信息
			uni.request({
				url: this.baseUrl+'getCourseByStuId', //仅为示例，并非真实接口地址。
				method:'POST',
				data: {
					stuId: uni.getStorageSync('uid')
				},
				header: {
					'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
				},
				success: (res) => {
					this.courseList=res.data.courseEntity;
				}
			});


		},
		methods:{
			courseItem:function(index){
				//点击某个科目
				this.currCourse=this.courseList[index].name;
				this.cid=this.courseList[index].id;
				this.bottomSHow=false;
			},
			selCourse:function(){
				//点击切换科目
				this.bottomSHow=true;
			},
			examDetail:function(index){
				var item=this.dataList[index];
				if(item.state=="已过期"){
					//跳转到结果页面 把考试编号传过去
					uni.navigateTo({
							url: '../examResult/examResult?targetId=' + item.id+'&type=1'
							// url: '../chapterquestion/examquestion?id=' + item.id
					})
				}else if(item.state=="未开始"){
					uni.showToast({
						title:"耐心等待开始哦！"
					})
				}else if(item.state=="考试中"){
					//开始做题并传过去试卷id
					uni.navigateTo({
						url: '../chapterquestion/examquestion?id=' + item.id
					})
				}
			},initExamList:function(){
				uni.request({
					url: this.baseUrl+'getTestPapers', //仅为示例，并非真实接口地址。
					method:'GET',
					data: {
						courseId:this.cid,
						chapterId:0,
						testMode:4
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
					},
					success: (res) => {
						this.dataList=res.data.testPaperList;
						
					},
				});
				
			}
		}
	}
</script>

<style>
	.top_div{
		height: 76rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #FFFFFF;
	}
	.top_div .top_left_div{
		font-size: 22rpx;
		color: #666666;
	}
	
	.top_div .top_right_div image{
		width: 20rpx;
		height: 20rpx;
	}
	.top_div .top_right_div text{
		font-size: 22rpx;
		margin-left: 20rpx;
		color: #e65e4f;
	}
	.paper_list{
		background: #FFFFFF;
	}
	.paper_item{
		display: flex;
		background: #FFFFFF;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1rpx solid #E8E8E8;
	}
	.paper_item .item_left{
		flex: 1;
	}
	.paper_item .item_left .paper_title{
		font-size: 26rpx;
		color: #333333;
	}
	.paper_item .item_left .paper_time{
		font-size: 22rpx;
		margin-top: 30rpx;
		color: #666666;
	}
	.paper_item .item_left .paper_time text:nth-child(1){
		margin-right: 20rpx;
	}
	.paper_item .item_right {
		font-size: 20rpx;		
	}
	.paper_item .item_right .gray_bg{
		height: 50rpx;
		border: 1rpx solid #999999;
		color: #999999;
		line-height: 50rpx;
		width: 110rpx;
		display: inline-block;
		text-align: center;
		border-radius: 25rpx;
	}
	
	.paper_item .item_right .green_bg{
		height: 50rpx;
		border: 1rpx solid #51c280;
		color: #51c280;
		line-height: 50rpx;
		width: 110rpx;
		display: inline-block;
		text-align: center;
		border-radius: 25rpx;
	}
	.paper_item .item_right .red_bg{
		height: 50rpx;
		border: 1rpx solid #e13b29;
		color: #e13b29;
		line-height: 50rpx;
		width: 110rpx;
		display: inline-block;
		text-align: center;
		border-radius: 25rpx;
	}
</style>
